﻿using System;
using Microsoft.Office.Interop.UccApi;

namespace shfa.snomtastic.systray.components
{
    public partial class uccInfo : _IUccSessionManagerEvents, _IUccSessionEvents
    {
        public event EventHandler onSessionStart;
        public event EventHandler onSessionEnd;

        public IUccSessionParticipant Caller;
        public IUccSession ActiveSession;

        #region Session Events

        protected void RaiseSessionStart()
        {
            if (onSessionStart != null)
                onSessionStart(this, new EventArgs());
        }

        protected void RaiseSessionEnd()
        {
            if (onSessionEnd != null)
                onSessionEnd(this, new EventArgs());
        }

        #endregion

        #region _IUccSessionManagerEvents Members

        void _IUccSessionManagerEvents.OnIncomingSession(IUccEndpoint pEventSource, UccIncomingSessionEvent pEventData)
        {
            if (pEventData.Session.Type == UCC_SESSION_TYPE.UCCST_AUDIO_VIDEO)
            {
                this.ActiveSession = pEventData.Session;
                Advise<_IUccSessionEvents>(pEventData.Session, this);
                Caller = pEventData.Inviter;
                RaiseSessionStart();
            }
        }

        void _IUccSessionManagerEvents.OnOutgoingSession(IUccEndpoint pEventSource, UccOutgoingSessionEvent pEventData) { }

        #endregion

        #region _IUccSessionEvents Members

        void _IUccSessionEvents.OnAddParticipant(IUccSession pEventSource, IUccOperationProgressEvent pEventData) { }

        void _IUccSessionEvents.OnRemoveParticipant(IUccSession pEventSource, IUccOperationProgressEvent pEventData) { }

        void _IUccSessionEvents.OnTerminate(IUccSession pEventSource, IUccOperationProgressEvent pEventData)
        {
            if (pEventSource.Type == UCC_SESSION_TYPE.UCCST_AUDIO_VIDEO)
                RaiseSessionEnd();
        }




        #endregion



    }
}
